// 定义塔数据结构
interface Tower {
  id: string;
  project_code: string;
  s_project_code: string;
  section_code: string;
  tower_name: string;
  lon: string;
  lat: string;
  last_tower: string;
  [key: string]: any; // 允许其他字段存在
}

// GeoJSON 点要素
interface GeoJSONPointFeature {
  type: "Feature";
  geometry: {
    type: "Point";
    coordinates: [number, number];
  };
  properties: Record<string, any>;
}

interface GeoJSONFeatureCollection {
  type: "FeatureCollection";
  features: GeoJSONPointFeature[];
}

/**
 * 生成塔的点 GeoJSON
 * @param towers 塔数据
 * @returns GeoJSON FeatureCollection
 */
export function towersToPointGeoJSON(towers: Tower[]): GeoJSONFeatureCollection {
  const features: GeoJSONPointFeature[] = towers.map(t => {
    const lon = parseFloat(t.lon);
    const lat = parseFloat(t.lat);

    return {
      type: "Feature",
      geometry: {
        type: "Point",
        coordinates: [lon, lat]
      },
      properties: {
        ...t // 把塔的所有属性都放到 properties
      }
    };
  });

  return {
    type: "FeatureCollection",
    features
  };
}
